//
//  MoreAdviViewController.m
//  WE
//
//  Created by iMacOne on 15/11/21.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "MoreAdviViewController.h"
#import "Size.h"
#import "ToolUtil.h"
#import "MoreDoctorCell.h"
#import "CityViewController.h"
#import "DoctorViewController.h"
#import "BaseView.h"
#import "Label+ImageButton.h"
@interface MoreAdviViewController (){
   
        BaseView *view;
        UISearchBar *searchBar1;
        UIView *sortView;
        UIView *sortView1;
        UIButton *cityButton;
        NSArray *hospitalArray;
        BaseView *blankView;
        UIView *screenView;
        UILabel *speedLabel;
        UILabel *rankLabel;
        BaseView *rubbishView;
        UIView *noUseView;
        Label_ImageButton *label;
        Label_ImageButton *imageButton;
        UIButton *bu;
        UIButton *butt;
   

}
@property (nonatomic, strong)UITableView * tableView;
@property (nonatomic, strong)UIButton *tmpBtn;
@property (nonatomic, strong)UIButton *mpBtu;
@end

@implementation MoreAdviViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"向专家资讯";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.tableView registerClass:[MoreDoctorCell class] forCellReuseIdentifier:@"MoreDoctorCell"];
    [self.view addSubview:self.tableView];
    [self creatBottomView];
    [self setupScreenView];
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
    }


}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
    
}

- (void)creatBottomView
{
    UIView *broundView = [[UIView alloc] initWithFrame:CGRectMake(0, WindowHeight - 49, WindowWidth, 49)];
    broundView.backgroundColor = [UIColor whiteColor];
    NSArray * arr = @[@"全国",@"消化内科",@"综合排序",@"筛选"];
    [ToolUtil createLine:0 superView:broundView lift:0 width:WindowWidth hight:1 color:GRAYCOLOR];
    for (int i = 0; i < arr.count; i++) {
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(i * WindowWidth /arr.count -1, 0, WindowWidth /arr.count -1, 49);
        btn.titleLabel.font = FONT(12);
        [btn setTitle:[NSString stringWithFormat:@"%@ ▴",arr[i]] forState:UIControlStateNormal];
        [ToolUtil createVerticalLine:0 superView:broundView lift:(i + 1) *WindowWidth/arr.count height:49];
        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        btn.tag = 100+i;
        [btn addTarget:self action:@selector(pressButton:) forControlEvents:UIControlEventTouchUpInside];
        [broundView addSubview:btn];
    }
    [self.view addSubview:broundView];
}
- (void)setupScreenView{
    blankView = [[BaseView alloc] initWithFrame:CGRectMake(0, 20*Height, WindowWidth, (WindowHeight - 20)/5 *3)];
    [blankView addTarget:self selector:@selector(pressScreenView)];
    blankView.hidden = YES;
    blankView.backgroundColor = [UIColor blackColor];
    blankView.alpha = 0.6;
    [self.view addSubview:blankView];
    screenView = [[UIView alloc] initWithFrame:CGRectMake(0, (WindowHeight - 20)/5 *3 + 20*Height, WindowWidth, (WindowHeight - 20)/5 *2)];
    screenView.backgroundColor = [UIColor whiteColor];
    screenView.hidden = YES;
    [self.view addSubview:screenView];
    UIImageView *screenImageV = [[UIImageView alloc] initWithFrame:CGRectMake(20*Width, 20*Height, 20*Width, 20*Height)];
    screenImageV.image = [UIImage imageNamed:@"iconfont-screen"];
    [screenView addSubview:screenImageV];
    UILabel *screenLabel = [[UILabel alloc] initWithFrame:CGRectMake(50*Width, 10*Height, 40*Width, 40*Height)];
    screenLabel.text = @"筛选";
    screenLabel.font = FONT(14);
    screenLabel.textColor = [UIColor blackColor];
    [screenView addSubview:screenLabel];
    
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    confirmButton.frame = CGRectMake(WindowWidth - 70*Width, 20*Height, 50*Width, 20*Height);
    [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    confirmButton.titleLabel.font = FONT(14);
    confirmButton.backgroundColor = [UIColor greenColor];
    [confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(pressconfirmButton) forControlEvents:UIControlEventTouchUpInside];
    [screenView addSubview:confirmButton];
    [ToolUtil createLine:60*Height superView:screenView lift:0 width:WindowWidth hight:1*Height color:[UIColor grayColor]];
    
    UILabel *timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20*Width, 80*Height, WindowWidth / 6 + 10 *Height, 20*Height)];
    timeLabel.text = @"候诊时间 :";
    timeLabel.font = FONT(14);
    timeLabel.backgroundColor = [UIColor whiteColor];
    timeLabel.textColor = [UIColor blackColor];
    [screenView addSubview:timeLabel];
    
    speedLabel = [[UILabel alloc] initWithFrame:CGRectMake(WindowWidth/6 + 30 *Width + WindowWidth / 30, 80*Height, WindowWidth / 6, 20*Height)];
    speedLabel.font = FONT(14);
    speedLabel.text = @"不限";
    speedLabel.textColor = [UIColor blueColor];
    speedLabel.backgroundColor = [UIColor whiteColor];
    [screenView addSubview:speedLabel];
    
    NSArray *arr = @[@"不限",@"非常快",@"比较快",@"一般"];
    for (int i = 0; i < arr.count; i++) {
        UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
        but.frame = CGRectMake(WindowWidth / 30 * (i + 1)+ WindowWidth/ 5 *i, 110*Height, WindowWidth / 5, 20*Height);
        but.backgroundColor = [UIColor colorWithRed:0.8371 green:0.8371 blue:0.8371 alpha:1.0];
        [but setTitle:arr[i] forState:UIControlStateNormal];
        [but setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        [but setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        but.titleLabel.font = FONT(14);
        [but addTarget:self action:@selector(pressbut:) forControlEvents:UIControlEventTouchUpInside];
        [screenView addSubview:but];
    }
    [ToolUtil createLine:150*Height superView:screenView lift:0 width:WindowWidth hight:1*Height color:[UIColor grayColor]];
    
    UILabel *levelLabel = [[UILabel alloc] initWithFrame:CGRectMake(20*Width, 170*Height, WindowWidth / 6 + 10 *Height, 20*Height)];
    
    levelLabel.text = @"医院级别 :";
    levelLabel.font = FONT(14);
    levelLabel.backgroundColor = [UIColor whiteColor];
    levelLabel.textColor = [UIColor blackColor];
    [screenView addSubview:levelLabel];
    rankLabel = [[UILabel alloc] initWithFrame:CGRectMake(WindowWidth/6 + 30 *Width + WindowWidth / 30, 170*Height, WindowWidth / 6, 20*Height)];
    rankLabel.font = FONT(14);
    rankLabel.text = @"不限";
    rankLabel.textColor = [UIColor blueColor];
    rankLabel.backgroundColor = [UIColor whiteColor];
    [screenView addSubview:rankLabel];
    
    NSArray *array = @[@"不限",@"三级甲等"];
    for (int i = 0; i < array.count; i++) {
        UIButton *but = [UIButton buttonWithType:UIButtonTypeCustom];
        but.frame = CGRectMake(WindowWidth / 30 * (i + 1)+ WindowWidth/ 5 *i, 210*Height, WindowWidth / 5, 20*Height);
        but.backgroundColor = [UIColor colorWithRed:0.8371 green:0.8371 blue:0.8371 alpha:1.0];
        [but setTitle:array[i] forState:UIControlStateNormal];
        [but setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        
        [but setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        but.titleLabel.font = FONT(14);
        [but addTarget:self action:@selector(pressLevelButton:) forControlEvents:UIControlEventTouchUpInside];
        [screenView addSubview:but];
    }
    
    
    rubbishView = [[BaseView alloc] initWithFrame:CGRectMake(0, 20, WindowWidth, (WindowHeight - 20)/5 *4)];
    [rubbishView addTarget:self selector:@selector(pressRubbishView)];
    rubbishView.hidden = YES;
    rubbishView.backgroundColor = [UIColor blackColor];
    rubbishView.alpha = 0.6;
    [self.view addSubview:rubbishView];
    
    noUseView = [[UIView alloc] initWithFrame:CGRectMake(0, (WindowHeight - 20)/5 *4, WindowWidth, (WindowHeight - 20)/5 + 20)];
    noUseView.hidden = YES;
    NSLog(@"%lf",noUseView.frame.size.height);
    noUseView.backgroundColor = [UIColor whiteColor];
    
    [self.view addSubview:noUseView];
    
    label = [Label_ImageButton buttonWithType:UIButtonTypeCustom];
    bu  = [label setupButtonFrame:CGRectMake(0, 0, WindowWidth, noUseView.frame.size.height / 2) title:@"综合排序" image:[UIImage imageNamed:@"iconfont-screen"]];
    
    [noUseView addSubview:bu];
    [bu addTarget:self action:@selector(pressLabel_Image:) forControlEvents:UIControlEventTouchUpInside];
    
    [ToolUtil createLine:noUseView.frame.size.height / 2 superView:noUseView lift:15*Height width:WindowWidth - 15*Height hight:1*Height color:[UIColor grayColor]];
    
    imageButton = [Label_ImageButton buttonWithType:UIButtonTypeCustom];
    
    
    butt = [imageButton setupButtonFrame:CGRectMake(0, noUseView.frame.size.height / 2 +1*Height, WindowWidth, noUseView.frame.size.height / 2 - 1*Height) title:@"预约量" image:[UIImage imageNamed:@"iconfont-right"]];
    [noUseView addSubview:butt];
    
    [butt addTarget:self action:@selector(pressLabel_Image:) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)pressLabel_Image:(UIButton*)imagebtu{
    
    if (bu == imagebtu) {
        imageButton.imageV.image = [UIImage imageNamed:@"iconfont-screen"];
        label.imageV.image = [UIImage imageNamed:@"iconfont-right"];
        rubbishView.hidden = YES;
        noUseView.hidden = YES;
    } else {
        label.imageV.image = [UIImage imageNamed:@"iconfont-screen"];
        imageButton.imageV.image = [UIImage imageNamed:@"iconfont-right"];
        rubbishView.hidden = YES;
        noUseView.hidden = YES;
    }
    
}

- (void)pressRanking{
    
}

- (void)pressRubbishView{
    rubbishView.hidden = YES;
    noUseView.hidden = YES;
}


- (void)pressLevelButton:(UIButton *)button{
    
    
    
    if (_mpBtu == nil){
        button.selected = YES;
        _mpBtu = button;
        button.backgroundColor = [UIColor blueColor];
    }
    else if (_mpBtu !=nil && _mpBtu == button){
        button.selected = YES;
        button.backgroundColor = [UIColor blueColor];
        
    }
    else if (_mpBtu!= button && _mpBtu!=nil){
        _mpBtu.selected = NO;
        _mpBtu.backgroundColor = [UIColor colorWithRed:0.8371 green:0.8371 blue:0.8371 alpha:1.0];
        button.selected = YES;
        button.backgroundColor = [UIColor blueColor];
        
        _mpBtu = button;
    }
    
    rankLabel.text = button.titleLabel.text;
}

- (void)pressbut:(UIButton *)btu{
    if (_tmpBtn == nil){
        btu.selected = YES;
        _tmpBtn = btu;
        btu.backgroundColor = [UIColor blueColor];
    }
    else if (_tmpBtn !=nil && _tmpBtn == btu){
        btu.selected = YES;
        btu.backgroundColor = [UIColor blueColor];
        
    }
    else if (_tmpBtn!= btu && _tmpBtn!=nil){
        _tmpBtn.selected = NO;
        _tmpBtn.backgroundColor = [UIColor colorWithRed:0.8371 green:0.8371 blue:0.8371 alpha:1.0];
        btu.selected = YES;
        btu.backgroundColor = [UIColor blueColor];
        
        _tmpBtn = btu;
    }
    
    speedLabel.text = btu.titleLabel.text;
    
}

- (void)pressconfirmButton{
    screenView.hidden = YES;
    blankView.hidden = YES;
}

- (void)pressScreenView{
    screenView.hidden = YES;
    blankView.hidden = YES;
    
}
- (void)pressButton:(UIButton *)btn
{
    if (btn.tag == 100) {
        
        [self presentViewController:[[CityViewController alloc] init] animated:YES completion:nil];
    }else if (btn.tag == 101){
        [self presentViewController:[[CityViewController alloc] init] animated:YES completion:nil];
    }else if (btn.tag == 102){
        rubbishView.hidden = NO;
        noUseView.hidden = NO;
    }else if (btn.tag == 103){
        blankView.hidden = NO;
        screenView.hidden = NO;
    }
}

- (UITableView *)tableView
{
    if (_tableView == nil) {
        self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0 ,WindowWidth , WindowHeight - 49 ) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        _tableView.rowHeight = 150;
        _tableView.showsVerticalScrollIndicator = NO;

        //        _tableView.scrollEnabled = NO;
    }
    return _tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 6;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellIdentifier = @"MoreDoctorCell";
    MoreDoctorCell * cell = [[MoreDoctorCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    DoctorViewController * doctorVC = [[DoctorViewController alloc] init];
    [self.navigationController pushViewController:doctorVC animated:YES];
    
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath

{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

@end
